﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Microsoft.Xna.Framework.Media;

namespace Elementum
{
    public static class MusicManager
    {
        //static List<Music> _musicList = new List<Music>();      //for music.
        //static List<String> _musicListName = new List<String>();//for music id
        static Dictionary<string, Music> _musicTable = new Dictionary<string, Music>();

        public static void AddMusic(String fromUrl, String id, float interval, bool looped)
        {
                Music nextToAdd = new Music(fromUrl, interval, looped);
                _musicTable.Add(id, nextToAdd);
        }

        public static Song LoadSong(String id) 
        {
                return ResourceManager.LoadSong(id);
        }

        public static void PlayMusic(String id)
        {
            //int toPlay = _musicListName.IndexOf(id);
            // _musicList[toPlay].MusicPlay();
                _musicTable[id].MusicPlay();
        }

        public static void PauseMusic(String id)
        {
            //int toPlay = _musicListName.IndexOf(id);
            //_musicList[toPlay].MusicPause();
                _musicTable[id].MusicPause();
        }

        public static void StopMusic(String id)
        {
            //int toPlay = _musicListName.IndexOf(id);
                _musicTable[id].MusicStop();
            
        }
        public static void FadeInMusic(String id)
        {
            //int toPlay = _musicListName.IndexOf(id);
                _musicTable[id].MusicVolumnFadeIn();
            
        }

        public static void FadeOutMusic(String id)
        {
            // int toPlay = _musicListName.IndexOf(id);
                _musicTable[id].MusicVolumnFadeOut();
            
        }

        public static void SetRePlay(bool set, String id)
        {
            //int toPlay = _musicListName.IndexOf(id);
            //_musicList[toPlay].Repeat = set
                _musicTable[id].Repeat = set;
            
        }

        public static void FreeAllMusic()
        {
            foreach (Music m in _musicTable.Values)
            {
                m.MusicFree();
            }
            _musicTable.Clear();
        }

        //public static List<Music> MusicList
        //{
        //    get 
        //    {
        //        return _musicList;
        //    }
        //}

        public static void SetVolume(string id, float volume)
        {
            // int toPlay = _musicListName.IndexOf(id);
                _musicTable[id].Volume = volume;
            
        }
        
    }
}
